<?php
@session_start();
//echo 'in';exit;
?>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="keywords" content="">
        <meta name="author" content="">
        <title>Cart</title>
        <?php fnGetMeta(); ?>
        <link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE; ?>css/payment.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE; ?>css/custom_product.css" />
        <script src="<?php echo URL . VIEW ?>js/cart_detail.js"></script>	

    </head>
    <body class="activateAppearAnimation header3" style="padding-top:0px;">
        <!-- Primary Page Layout 
                ================================================== --> 
        <!-- globalWrapper -->
        <div id="globalWrapper" class="localscroll">
            <?php fnGetHeader(); ?>

            <section class="inner_banner">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-6">

                            <ul id="navTrail">
                                <li><a href="<?php echo SITEURL;?>">Home</a></li>
                                <li id="navTrailLast">Cart</li>
                            </ul>
                        </div>
                        <div class="col-sm-6 hidden-xs"></div>
                    </div>
                </div>
            </section>
            <section class="titles">
                <div class="container">
                    <h2><span>Get 24/7 Trusted PC Solution</span> Online from Trained Tech Experts through Secure Remote Access at TechOak</h2>
                </div>
            </section>
            <section>
                <div class="container">
                    <div class="row">

                        <div class="col-lg-12 mt15 proudct-page">

                            <div class="innerpage">

                                <div class="view-cart-page-div">
                                    <h3>Cart</h3>

                                    <div class="view-cart-top clearfix">

                                        <a href="<?php echo URL . "product"; ?>" class="continue-shopping"><i class="text-arrow">←</i>&nbsp;Continue Shopping</a>

                                        <?php if ($this->Final_amount_with_discount == 0) { ?>
                                            <a href="#"  class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } else if ($this->Final_amount_with_discount > 0 && (isset($_SESSION['coupon_detail']) && $_SESSION['coupon_detail']['coupon_staus'] == 'valid' )) { ?>
                                            <a href="<?php echo URL . "checkout"; ?>" class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } else if ($this->Final_amount_with_discount > 0  ) { ?>
                                            <a href="<?php echo URL . "checkout"; ?>" class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php }else { ?>
                                            <a href="#"  class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } ?>
                                    </div><!-- end of view-cart-top -->

                                    <div class="view-cart-container clearfix">
                                        <?php
                                        //  echo '<pre>';print_R($_SESSION['shoping_cart']);exit;
                                        if (isset($_SESSION['view_message']) && $_SESSION['view_message'] != ""):
                                            ?>
                                            <div id="msg" class="alert alert-success" style="opacity: 0.846072;">
                                                <button data-dismiss="alert" class="close" type="button">×</button>
                                                <i class="fa fa-ok-sign"></i> 
                                                <?php
                                                echo $_SESSION['view_message'];
                                                unset($_SESSION['view_message']);
                                                ?>
                                            </div>
                                        <?php endif; ?>
                                        <?php if ($this->ErrorMessage != ""): ?>
                                            <div id="msg" class="alert alert-danger" style="opacity: 0.846072;">
                                                <button data-dismiss="alert" class="close" type="button">×</button>
                                                <i class="fa fa-ok-sign"></i> <?php echo $this->ErrorMessage; ?>
                                            </div>
                                        <?php endif; ?>
                                        <?php
                                        if (count($this->errorMessageArray) > 0):
                                            foreach ($this->errorMessageArray as $e_key => $e_value):
                                                ?>
                                                <div id="msg" class="alert alert-danger" style="opacity: 0.846072;">
                                                    <button data-dismiss="alert" class="close" type="button">×</button>
                                                    <i class="fa fa-ok-sign"></i> <?php echo $e_value; ?>
                                                </div>
                                            <?php endforeach;
                                        endif; ?>





                                        <div class="cart-table clearfix">
                                            <div class="head-td clearfix">
                                                <div class="row1">Product</div>
                                                <div class="row2">Unit Price</div>
                                                <div class="row3">Quantity</div>
                                                <div class="row4">Total Price</div>
                                            </div><!-- end of head-td -->


                                            <?php
                                            $total_Amount = "";
                                            if (isset($_SESSION['shoping_cart']) && count($_SESSION['shoping_cart']) > 0):

                                                $coupon_amt = '0';
                                                $coupon_category = '';
                                                $cat_match_count = 1;
                                                $cat_match_qty = 1; 
                                                $coupon_applied = '';
                                                $coupon_product = '';

                                                if (isset($_SESSION['coupon_detail'])) {
                                                    if ($_SESSION['coupon_detail']['coupon_applied'] == 'per_item') {
                                                        $cat_match_count = 0;
                                                        $cat_match_qty = 0;
                                                        $coupon_applied = 'per_item';
                                                        $coupon_amt = $_SESSION['coupon_detail']['coupon_price'];
                                                        $coupon_category = $_SESSION['coupon_detail']['coupon_category'];
                                                        $coupon_product = $_SESSION['coupon_detail']['coupon_product'];
                                                    }
                                                }


                                                foreach ($_SESSION['shoping_cart'] as $key => $prd_value):
                                                    if ($prd_value['prd_cat_id'] != '') {
                                                        if (($prd_value['prd_cat_id'] == $coupon_category) && ($coupon_applied == 'per_item')) {
                                                            $cat_match_count +=1;
                                                            $cat_match_qty +=$prd_value['prd_qty'];
                                                            
                                                        }
                                                    }
                                                    
                                                     if ($prd_value['prd_id'] != '') {
                                                        if (($prd_value['prd_id'] == $coupon_product) && ($coupon_applied == 'per_item')) {
                                                            $cat_match_count +=1;
                                                            $cat_match_qty +=$prd_value['prd_qty'];
                                                        }
                                                    }

                                                    /* else{
                                                      $prd_match_price = $prd_value['prd_qty'] * $prd_value['prd_price'];
                                                      } */
                                                    $total_Amount += $prd_value['prd_qty'] * $prd_value['prd_price'];
                                                    if ($prd_value['prd_image'] != ""):
                                                        if (file_exists("admin/" . $prd_value['prd_image'])):
                                                            $src = URL . "admin/" . $prd_value['prd_image'];
                                                        else:
                                                            $src = URL . "img/images/default-product-image.jpg";
                                                        endif;

                                                    else:
                                                        $src = URL . "img/images/default-product-image.jpg";
                                                    endif;
                                                    ?>
                                                    <div class="body-td clearfix quantity-container">
                                                        <form method="post" class="cartfrm" > <div class="row1">

                                                                <?php if ($prd_value['prd_id'] == 17): ?>

                                                                    <img src="<?php echo $src; ?>" height="150" width="150" alt="">
                                                                    <span><?php echo ucfirst($prd_value['prd_name']); ?></span>
                                                                <?php else: ?>
                                                                    <a href="<?php echo URL . "product_listing/" . $prd_value['prd_id']; ?>">
                                                                        <img src="<?php echo $src; ?>" height="150" width="150" alt="">
                                                                        <span><?php echo ucfirst($prd_value['prd_name']); ?></span>
                                                                    </a>
                                                                <?php endif; ?>


                                                                <!--<a href="#" class="close-btn">close</a>-->

                                                                <input type="hidden" name="product_id" id="product_id" value="<?php echo $prd_value['prd_id']; ?>" />
                                                                <input type="submit" name="remove_product" class="close-btn-sub" value="">

                                                            </div> 

                                                            <div class="row2">$<?php echo number_format($prd_value['prd_price'], 2); ?></div>
                                                            <!--<div class="row2"><?php echo $prd_value['prd_qty']; ?></div>
                                                            -->
                                                            <div class="row3">
                                                                <div class="product-fields-wrapper clearfix">
                                                                    <div class="product-fields-group clearfix">
                                                                        <div class="qty clearfix changer">
                                                                            <div class="value-changer ">
                                                                                <a class="increase quantity_plus" href="#">+</a>
                                                                                <input type="text" value="<?php
                                                                if (!isset($this->quantity_numb)):
                                                                    echo $prd_value['prd_qty'];
                                                                else:
                                                                    echo $this->quantity_numb;
                                                                endif;
                                                                ?>" readonly="readonly" name="quantity" class="amount-input quantity" size="5">
                                                                                <a class="decrease quantity_minus" href="#">−</a>
                                                                            </div>

                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </form>
                                                        <!-- end of row 3 -->
                                                        <div class="row4">$<?php
                                                                        //$final_amt_product = ($prd_value['prd_qty'] * $prd_value['prd_price']) - $coupon_amt;
                                                                        echo number_format($prd_value['prd_qty'] * $prd_value['prd_price'], 2);
                                                                ?></div>
                                                    </div>
                                                    <?php
                                                endforeach;
                                            else:
                                                echo '<b> There are no items in this cart. </b>';
                                            endif;
                                            ?>




                                        </div><!-- end of cart-table -->
                                        <?php if (isset($_SESSION['shoping_cart']) && count($_SESSION['shoping_cart']) > 0): ?>
                                            <div class="cart-table-bottom clearfix">
                                                <form method="POST" id="promo_form">
                                                    <div class="promo-code">
                                                        <input name="coupon_code" id="coupon_code" type="password"  value="<?php if (isset($_SESSION['coupon_detail']) && $_SESSION['coupon_detail']['coupon_code'] != ''):echo $_SESSION['coupon_detail']['coupon_code'];
                                            endif;
                                            ?>" placeholder="COUPON CODE" class="promo-input">
                                                       
                                                        <input name="go_coupon_code" type="submit" value="go" class="go-btn">
                                                       &nbsp;&nbsp;
                                                         <input name="remove_coupon_code" type="submit" value="Remove Code" class="go-btn">
                                                    </div>
                                                    <div class="clearfix"></div>
                                                     <br/>
                                                        <input type="checkbox" name="show_coupon" id="show_coupon" value="1"/> 
                                                        <label for="show_coupon">Show Coupon code</label>
                                                </form>
                                                <div class="cart-total  clearfix">
                                                    <span class="total-1"><label>Subtotal</label></span>
                                                    <span class="total-2"><label>$<?php echo number_format($total_Amount, 2); ?></label></span>
                                                </div>
                                                <div class="clearfix"></div>
                                                <div class="cart-total  clearfix">
                                                    <span class="total-1"><label>Discount Value</label></span>
                                                    <span class="total-2"><label>$ 
                                                            <?php
                                                            // echo $cat_match_count."==";
                                                           // echo $cat_match_qty."===".$cat_match_count;
                                                            if (isset($_SESSION['coupon_detail']) && $_SESSION['coupon_detail']['coupon_price'] != ''):
                                                                echo number_format(( $cat_match_qty * $_SESSION['coupon_detail']['coupon_price']), 2);
                                                            else:
                                                                echo '0';
                                                            endif;
                                                            ?> 
                                                        </label></span>
                                                </div>
                                                <div class="clearfix"></div>
                                                <div class="cart-total no-bdr clearfix">
                                                    <span class="total-1"><label>Total</label></span>
                                                    <span class="total-2"><label>$<?php
                                                        $coupon_value = 0;
                                                        if (isset($_SESSION['coupon_detail']) && $_SESSION['coupon_detail']['coupon_price'] != ''):
                                                            /* if($_SESSION['coupon_detail']['coupon_applied'] == 'per_item' ){
                                                              $coupon_value = 0;
                                                              }else if($_SESSION['coupon_detail']['coupon_staus'] == 'valid' ){
                                                             */
                                                            $coupon_value = /*$cat_match_count **/ $cat_match_qty * $_SESSION['coupon_detail']['coupon_price'];
                                                        //}

                                                        endif;
                                                        echo number_format(($total_Amount - $coupon_value), 2);

                                                        //echo number_format($total_Amount, 2);
                                                            ?></label></span>
                                                </div>

                                            </div>

                                            <!-- end of cart-table-bottom -->
                                        <?php endif; ?>


                                    </div><!-- end of view-cart-container -->

                                    <div class="view-cart-top clearfix">

                                        <a href="<?php echo URL . "product"; ?>" class="continue-shopping"><i class="text-arrow">←</i>&nbsp;Continue Shopping</a>
                                        <?php
//echo $this->Final_amount_with_discount;
                                        if ($this->Final_amount_with_discount == 0) {
                                            ?>
                                            <a href="#"  class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } else if ($this->Final_amount_with_discount > 0 && (isset($_SESSION['coupon_detail']) && $_SESSION['coupon_detail']['coupon_staus'] == 'valid' )) { ?>
                                            <a href="<?php echo URL . "checkout"; ?>" class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } else if ($this->Final_amount_with_discount > 0  ) { ?>
                                            <a href="<?php echo URL . "checkout"; ?>" class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } else { ?>
                                            <a href="#"  class="proceedtocheckout">
                                                Proceed To Checkout&nbsp;<i class="text-arrow">→</i>
                                            </a>
                                        <?php } ?>

                                    </div><!-- end of view-cart-top -->

                                </div><!-- end of view-cart-page-div -->


                            </div>


                        </div>




                    </div>
                </div>

        </div>
    </section>


    <div id="contentBk" class="clearfix">
        <?php fnGetHmFooter(); ?>
</body>
</html>